package com.study.controller;

import com.study.anno.OpLog;
import com.study.entity.Emp;
import com.study.entity.EmpQueryParam;
import com.study.entity.PageBean;
import com.study.entity.Result;
import com.study.mapper.EmpMapper;
import com.study.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;



    /*@GetMapping("/emps")//分页查询
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        PageBean pageBean = empService.list(page,pageSize);
        return Result.success(pageBean);
    }*/

    @GetMapping//条件分页查询
    public Result list(EmpQueryParam param) {
        log.info("接收到条件分页查询参数：" + param.toString());
        PageBean pageBean = empService.list(param);
        return Result.success(pageBean);
    }
    @OpLog
    @PostMapping
    public Result add(@RequestBody Emp emp) {
        empService.add(emp);
        return Result.success();
    }
    @OpLog
    @DeleteMapping
    public Result remove(Integer[] ids) {//参数用集合的话需要用@RequestParam注解
        empService.remove(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        Emp emp = empService.selecyById(id);
        return Result.success(emp);
    }
    @OpLog
    @PutMapping
    public Result update(@RequestBody Emp emp) {
        empService.update(emp);
        return Result.success();
    }
    @GetMapping("/list")
    public Result listAll(){
        List<Emp> list = empService.listAll();
        return Result.success(list);
    }
}
